const mongoose = require('mongoose')
const Schema = mongoose.Schema
const Mixed = Schema.Types.Mixed
// 0、待进入1、猜题中2、作画中 // 0未使用1、使用中
const creatHouseSchema = new mongoose.Schema({
  house_id: String,
  creat_id: String,
  name: String,
  avatarUrl: String,
  gender: Number,
  status: Number,
  problems_count: Number,
  surplus_problems_count: Number,
  members: [{
    openid: String,
    name: String,
    avatarUrl: String,
    gender: Number,
    m_status: Number,
    score: Number,
    updatedAt: {
      type: Number,
      default: parseInt(new Date().getTime() / 1000)
    }

  }],
  meta: {
    createdAt: {
      type: Number,
      default: parseInt(new Date().getTime() / 1000)
    },
    updatedAt: {
      type: Number,
      default: parseInt(new Date().getTime() / 1000)
    }
  }
})
creatHouseSchema.pre('save', function(next) {
  const time = parseInt(new Date().getTime() / 1000)
  if (this.isNew) {
    this.meta.createdAt = this.meta.updatedAt = time
  } else {
    this.meta.updatedAt = time
  }
  next()
})
export const creatHouse = mongoose.model('creatHouse', creatHouseSchema)
